﻿using System;
using System.Linq;
using DZLib.ExtendFramework.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace DZLib.ExtendFramework.UnitTests.Generic.ExtendIEnumerableTest
{
    [TestClass]
    public class SubTest
    {
        [TestMethod]
        public void SubOnlyIndexTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            var testTarget = testCase.Sub(4).ToArray();
            var expected = new int[] { 5, 6, 7, 8, 9, 0 };
            Assert.IsTrue(testTarget.SequenceEqual(expected));
        }

        [TestMethod]
        public void SubOnlyIndexLowBoundTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            try
            {
                var testTarget = testCase.Sub(-1).ToArray();
            }
            catch (IndexOutOfRangeException)
            {
                Assert.IsTrue(true);
            }
        }

        [TestMethod]
        public void SubOnlyIndexUpBoundTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            var testTarget = testCase.Sub(9).ToArray();
            var expected = new int[] { 0 };
            Assert.IsTrue(testTarget.SequenceEqual(expected));
        }

        [TestMethod]
        public void SubLengthTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            var testTarget = testCase.Sub(4, 3).ToArray();
            var expected = new int[] { 5, 6, 7 };
            Assert.IsTrue(testTarget.SequenceEqual(expected));
        }

        [TestMethod]
        public void SubLengthLowBoundTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            try
            {
                var testTarget = testCase.Sub(4, 0).ToArray();
            }
            catch (IndexOutOfRangeException)
            {
                Assert.IsTrue(true);
            }
        }

        [TestMethod]
        public void SubLengthUpBoundTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            var testTarget = testCase.Sub(9, 1).ToArray();
            var expected = new int[] { 0 };
            Assert.IsTrue(testTarget.SequenceEqual(expected));
        }

        [TestMethod]
        public void SubLengthUpBoundOverTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            try
            {
                var testTarget = testCase.Sub(9, 2);
            }
            catch (IndexOutOfRangeException)
            {
                Assert.IsTrue(true);
            }
        }
    }
}
